package offer;

import java.util.Stack;

public class EX9 {
    Stack<Integer> s1;
    Stack<Integer> s2;

    public EX9() {
        s1 = new Stack<Integer>();
        s2 = new Stack<Integer>();
    }

    public void appendTail(int value) {
        if(s2.isEmpty()){
            s1.push(value);
        }else{
            while(!s2.isEmpty()){
                s1.push(s2.pop());
            }
            s1.push(value);
        }
    }

    public int deleteHead() {
        if(s1.isEmpty()){
            if(s2.isEmpty()){
                return -1;
            }else{
                return s2.pop();
            }
        }else{
            while (!s1.isEmpty()){
                s2.push(s1.pop());
            }
            return s2.pop();
        }
    }
}
